/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.landmark;

import java.io.File;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;



/**
 *
 * @author computer
 */
public class RemoveDuplicatesSKURowsGUI extends GenerateSKUID{
    JFileChooser fc;

    /**
     * Creates new form RenameFileGUI
     */
    public RemoveDuplicatesSKURowsGUI() {
        initComponents();
        fc = new JFileChooser();
        
        fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
        fc.setCurrentDirectory(new File("D:\\Projects -1\\Catalogs\\Barco"));
        fc.setFileFilter(new FileFiltering());
        //fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
        fc.setMultiSelectionEnabled(false);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        txtInputFolder = new javax.swing.JTextField();
        btnInputFolder = new javax.swing.JButton();
        txtOutputFolder = new javax.swing.JTextField();
        btnRemoveDupSKU = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        btnOutputFolder = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTextArea1 = new javax.swing.JTextArea();

        setBackground(new java.awt.Color(0, 113, 187));
        setFont(new java.awt.Font("Cambria", 0, 11)); // NOI18N

        txtInputFolder.setFont(new java.awt.Font("Cambria", 0, 12)); // NOI18N

        btnInputFolder.setFont(new java.awt.Font("Cambria", 0, 12)); // NOI18N
        btnInputFolder.setText("...");
        btnInputFolder.setToolTipText("Select the folder with images");
        btnInputFolder.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnInputFolderActionPerformed(evt);
            }
        });

        txtOutputFolder.setFont(new java.awt.Font("Cambria", 0, 12)); // NOI18N

        btnRemoveDupSKU.setFont(new java.awt.Font("Cambria", 0, 12)); // NOI18N
        btnRemoveDupSKU.setText("Remove Duplicates Rows");
        btnRemoveDupSKU.setToolTipText("Remove Duplicates Rows");
        btnRemoveDupSKU.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnRemoveDupSKUActionPerformed(evt);
            }
        });

        jLabel1.setFont(new java.awt.Font("Cambria", 0, 12)); // NOI18N
        jLabel1.setForeground(new java.awt.Color(255, 255, 255));
        jLabel1.setText("Output File Path :");

        jLabel2.setFont(new java.awt.Font("Cambria", 0, 12)); // NOI18N
        jLabel2.setForeground(new java.awt.Color(255, 255, 255));
        jLabel2.setText("Input File Path:");

        btnOutputFolder.setFont(new java.awt.Font("Cambria", 0, 12)); // NOI18N
        btnOutputFolder.setText("...");
        btnOutputFolder.setToolTipText("Select the folder with images");
        btnOutputFolder.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnOutputFolderActionPerformed(evt);
            }
        });

        jTextArea1.setBackground(new java.awt.Color(51, 51, 51));
        jTextArea1.setColumns(20);
        jTextArea1.setForeground(new java.awt.Color(255, 255, 51));
        jTextArea1.setLineWrap(true);
        jTextArea1.setRows(5);
        jTextArea1.setText("Input file which contains SKU_ID and MAN_SKU_ID columns blank. \nOutput file is where you want the output file to be created.");
        jScrollPane1.setViewportView(jTextArea1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jScrollPane1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnRemoveDupSKU))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(txtInputFolder, javax.swing.GroupLayout.PREFERRED_SIZE, 305, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel1)
                                    .addComponent(txtOutputFolder, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 305, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(btnInputFolder)
                                    .addComponent(btnOutputFolder, javax.swing.GroupLayout.Alignment.TRAILING)))
                            .addComponent(jLabel2))
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(6, 6, 6)
                .addComponent(jLabel2)
                .addGap(4, 4, 4)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtInputFolder, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnInputFolder))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtOutputFolder, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnOutputFolder))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(23, 23, 23)
                        .addComponent(btnRemoveDupSKU))
                    .addGroup(layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void btnRemoveDupSKUActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRemoveDupSKUActionPerformed

        if( txtInputFolder.getText().trim().equals("") ) {
            JOptionPane.showMessageDialog(this, "Please select a input file", "Error", JOptionPane.OK_CANCEL_OPTION);            
        }else if( txtOutputFolder.getText().trim().equals("") ) {
            JOptionPane.showMessageDialog(this, "Please select a output file to save", "Error", JOptionPane.OK_CANCEL_OPTION);
        } else {
            //Util.getHelperBean().setInputFile(fc.getSelectedFile().toString());
            try{
            new RemoveDuplicatesSKURowsSwingWorker().execute();
            }catch(Exception e ) {
                e.printStackTrace();
            }
        }        
    }//GEN-LAST:event_btnRemoveDupSKUActionPerformed

    private void btnInputFolderActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnInputFolderActionPerformed
        // TODO add your handling code here:
        //Handle open button action.
        if (evt.getSource() == btnInputFolder) {
            int returnVal = fc.showOpenDialog(this);
            
            if (returnVal == JFileChooser.APPROVE_OPTION) {
                File file = fc.getSelectedFile();
                //System.out.println(fc.getSelectedFile().toString());                
                Util.getHelperBean().setInputFile(fc.getSelectedFile().toString());
                txtInputFolder.setText(fc.getSelectedFile().toString());
                //This is where a real application would open the file.
                //log.append("Opening: " + fc.getSelectedFile() + "." + newline);
            } else {
                JOptionPane.showMessageDialog(this, "Cancelled");
            }
            //log.setCaretPosition(log.getDocument().getLength());
 
        //Handle save button action.
        } 
    }//GEN-LAST:event_btnInputFolderActionPerformed

    private void btnOutputFolderActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnOutputFolderActionPerformed
        if (evt.getSource() == btnOutputFolder) {
            //fc.addChoosableFileFilter(new FileFiltering());
            int returnVal = fc.showOpenDialog(this);
            
            if (returnVal == JFileChooser.APPROVE_OPTION) {
                File file = fc.getSelectedFile();
                //System.out.println(fc.getSelectedFile().toString());
                Util.getHelperBean().setOutputFilePath(fc.getSelectedFile().toString());
                txtOutputFolder.setText(fc.getSelectedFile().toString());
                //This is where a real application would open the file.
                //log.append("Opening: " + fc.getSelectedFile() + "." + newline);
            } else {
                JOptionPane.showMessageDialog(this, "Cancelled");
            }
            //log.setCaretPosition(log.getDocument().getLength());
 
        //Handle save button action.
        } 
    }//GEN-LAST:event_btnOutputFolderActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnInputFolder;
    private javax.swing.JButton btnOutputFolder;
    private javax.swing.JButton btnRemoveDupSKU;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextArea jTextArea1;
    protected javax.swing.JTextField txtInputFolder;
    protected javax.swing.JTextField txtOutputFolder;
    // End of variables declaration//GEN-END:variables
}
